import { createStore } from "vuex";
import createPersistedState from "vuex-persistedstate";
export default createStore({
  state: {
    token: "", // 存储的token
    userinfo: {}, // 用户信息
    loginTime:"", // 登录时间
    isCollapse: false, // 实现展开列表
  },
  mutations: {
    setToken(state, token) {
      state.token = token;
    },
    setUserInfo(state, info) {
      state.userinfo = info;
    },
    changeCollapse(state, value) {
      state.isCollapse = value;
    },
    setLoginTime(state, value){
      state.loginTime = value
    }
  },
  actions: {},
  modules: {},
  plugins: [
    createPersistedState({
      storage: window.sessionStorage,
      key: "my-Commerce",
      render(state) {
        // 要存储的数据:采用扩展运算符 的方式存储了state中的所有数据
        return { ...state };
      },
    }),
  ],
});
